import Sequelize from 'sequelize';
import express from 'express';
import { statusList, sequelizeStatus } from '../../common/status'; // 状态码对照
import { User } from '../../modal/index'; // 数据库实体类
import { checkPermission } from '../../utils/utils'; // 工具类

const router = express.Router();
const permission = ["all"];

router.post('/', async function (Request, Response, next) {
  //权限校验
  await checkPermission(Request, Response, permission)
  let uid = JSON.parse(Request.signedCookies.token).uid
  User.Modal.findAll({
    where: {
      id: uid,
    },
    attributes: { exclude: ['password'] } // 过滤字段
  }).then(res => {
    if (res && res.length > 0) {
      Response.json({
        data: {
          userInfo: res[0]
        },
        message: "success"
      });
    } else {
      Response.status(300).send({ message: "用户查询失败" });
    }
  }).catch(err => {
    console.log(err)
    Response.status(500).send({ message: sequelizeStatus[err.name] || statusList[500] || err.name });
  });
});

module.exports = router;